var basename = require('path').basename;
var config = require('./config');
var amqCon = require('../../common/util/AMQConnection');
var log4js = require('log4js');
var logger = log4js.getLogger('DaifugoTableManager');
var manager = require('../../common/game/TableManager');

log4js.configure('./log4js.conf.json', {});

/*var keys = process.argv.slice(2);
if (keys.length < 1) {
    console.log('Usage %s pattern [pattern...]',
                basename(process.argv[1]));
    process.exit(1);
}*/

logger.info('start daifugo Tablemanager server');
var aCon = amqCon.getInstance();
aCon.connect(config.common.amq.host, config.common.amq.port, function(result) {
    if (result === true) {
        logger.info('connect to rabbit server');
        var tablemng = new manager.TableManager(config);
        tablemng.init(function(result2) {
            if (result2 === true) {
                logger.info('start server ok. wait for connections');
            } else {
                logger.error('cannot start server');
            }
        });
    } else {
        logger.error('cannot connect to rabbit server, exit now!!!');
    }
});
